package cn.iot.controller.sys;

import cn.iot.common.dto.ResultMsg;
import cn.iot.netty.service.SendInstructsService;
import cn.iot.sys.entity.SysEwDevice;
import cn.iot.sys.service.SysEwDeviceService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Map;

@RestController
@RequestMapping("/sys/ewdevice")
public class SysEwDeviceController {
    @Resource
    private SysEwDeviceService sysEwDeviceService;
    @Resource
    private SendInstructsService sendInstructsService;


    private Logger logger = LoggerFactory.getLogger(getClass());

    /**
     *发送指令
     */
    @PostMapping("/electricity")
    public ResultMsg operationElectricity(@RequestParam String operationType,@RequestParam int id){
        logger.info("SysEwDeviceController operationElectricity operationType{},id{}",operationType,id);
        ResultMsg msg = sendInstructsService.operationElectricity(operationType,id);
        logger.debug("SysEwDeviceController operationElectricity mag",msg);
        return msg;
    }

    /**
     * 操作记录
     */
    @PostMapping("/getSysEwdevicelog")
    public ResultMsg getSysEwdevicelog(@RequestParam Map<String,Object> map){
        logger.info("SysEwDeviceController getSysEwdevicelog map{}",map);
        ResultMsg msg = sendInstructsService.getSysEwdevicelog(map);
        logger.debug("SysEwDeviceController callbackInstructResultMsg mag",msg);
        return msg;
    }

    /**
     * 电表参数
     */
    @PostMapping("/getSysElectricityInfo")
    public ResultMsg getSysElectricityInfo(@RequestParam int id){
        logger.info("SysEwDeviceController getSysElectricityInfo id{}",id);
        ResultMsg msg = sendInstructsService.getSysElectricityInfo(id);
        logger.debug("SysEwDeviceController callbackInstructResultMsg mag",msg);
        return msg;
    }



    @PostMapping("getEwDeviceList")
    public ResultMsg getEwDeviceList(@RequestParam Map<String,Object> map){
        logger.info("SysEwDeviceController getEwDeviceList map{}",map);
        ResultMsg msg = sysEwDeviceService.getEwDeviceList(map);
        logger.debug("SysEwDeviceController getEwDeviceList msg{}",msg);
        return msg;
    }

    @PostMapping("addEwDevice")
    public ResultMsg addEwDevice(@RequestBody SysEwDevice sysEwDevice){
        logger.info("SysEwDeviceController addEwDevice sysEwDevice{}",sysEwDevice);
        ResultMsg msg = sysEwDeviceService.addEwDevice(sysEwDevice);
        logger.debug("SysEwDeviceController addEwDevice msg{}",msg);
        return msg;
    }
    @PostMapping("updEwDevice")
    public ResultMsg updEwDevice(@RequestBody SysEwDevice sysEwDevice){
        logger.info("SysEwDeviceController updEwDevice sysEwDevice{}",sysEwDevice);
        ResultMsg msg = sysEwDeviceService.updEwDevice(sysEwDevice);
        logger.debug("SysEwDeviceController updEwDevice msg{}",msg);
        return msg;
    }
    @PostMapping("delEwDeviceById")
    public ResultMsg delEwDeviceById(@RequestParam int id){
        logger.info("SysEwDeviceController delEwDeviceById id{}",id);
        ResultMsg msg = sysEwDeviceService.delEwDeviceById(id);
        logger.debug("SysEwDeviceController updEwDevice msg{}",msg);
        return msg;
    }
}
